<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>质检入库列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../res/layui-v2.5.6/css/layui.css" media="all">
    <script type="text/javascript" src="../../../res/js/jquery-3.4.1.min.js"></script>
</head>
<body>


<div>
    <div class="layui-inline" style="margin-top: 20px;margin-left: -45px">
        <label class="layui-form-label">备注:</label>
        <div class="layui-input-inline">
            <input type="text" name="remark" id="remark" required lay-verify="required"  placeholder="请输入备注" maxlength="200" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-inline" style="margin-top: 20px">
        <label class="layui-form-label">入库时间:</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" id="appearTime" name="appearTime" placeholder="yyyy-MM-dd">
        </div>
    </div>
    <div class="layui-btn-group demoTable" style="margin-top: 20px;margin-left: 30px">
        <button class="layui-btn" data-type="getCheckData" id="add">一键质检入库</button>
    </div>

</div>

<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="toolbarDemo">
    <div class="demoTable">
        搜索：
        <div class="layui-inline">
            <input class="layui-input" name="drugName" id="drugName" autocomplete="off" placeholder="请输入药品名称">
        </div>
        <button class="layui-btn" data-type="reload" id="sousuo" onclick="seach(this)" style="margin-left: 10px">搜索</button>
    </div>
</script>

<script type="text/javascript" src="../../../res/layui-v2.5.6/layui.js"></script>
<script>
    var openIndex = null;
    var table = null;
    var laydate = null;
    layui.use(['table', 'laydate'], function () {
        table = layui.table;
        laydate = layui.laydate;

        //日期选择框
        laydate.render({
            elem: '#appearTime'
        });

        table.render({
            method:"POST",
            elem: '#test'
            , url: '/immPurchaseDeatis/queryAll'
            , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            , defaultToolbar: false
            , title: '入库明细数据表'
            , cols: [[
                {field: 'drugName', title: '药品名称', width: 140,align:"center" }
                , {field: 'count', title: '入库数量', width: 150,align:"center"}
                , {field: 'money', title: '采购价', width: 100,align:"center"}
                , {field: 'operator', title: '采购人', width: 170,align:"center"}
                , {field: 'operatingTime', title: '采购时间', width: 170,align:"center"}
                , {field: 'remark', title: '备注', width: 120,align:"center"}
            ]]
            , page: true
            , id: 'test'
            ,where: {
                purchaseId:getQueryString("id"),
            }

        });


        var $ = layui.$;
        $('#add').on('click', function(){
            var remark = $("#remark").val();
            var appearTime = $("#appearTime").val();
            var datas = layui.table.cache["test"];
            console.info(datas);

            if(remark == ""){
                layer.msg('请输入备注');
            }else if(appearTime == ""){
                layer.msg('请填写入库时间');
            }else{
                $.ajax({
                        url:"/immRepertory/ruku",
                        data:{"remark":remark,"appearTime":appearTime,"purchaseDeatis":JSON.stringify(datas)},
                        type: "post",
                        dataType:"json",
                        cache:false,
                        async: false,
                        success: function(obj){
                            if(obj.status==20){
                                parent.closeOpen(obj.message);
                            }else{
                                parent.closeOpen(obj.message);
                            }
                        }
                    });
                }
                return false;
        });


    });


    /**
     得到地址栏的参数
     */
    function getQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    }

    //搜索
    function seach() {
        var drugName = $("#drugName").val();
        table.reload('test', {
            where: {
                drugName: drugName,
            },
            page: {
                curr: 1//从第一页开始查询
            }
        });
    }
</script>
</body>
</html>